package com.bocek.chakmapoint.controller;

import java.util.ArrayList;

import com.bocek.chakmapoint.model.Slide;
import com.bocek.chakmapoint.model.SlideList;

public class SlideSortController {

	private static SlideSortController instance = null;

	private int selectedSlideNo;
	private Slide selectedSlide;
	private String currentState = null;

	private SlideSortController() {
		currentState = "idle";
	}

	public static SlideSortController getInstance() {
		if (instance == null) {
			instance = new SlideSortController();
		}

		return instance;
	}

	public void activate() {
		currentState = "idle";
	}

	/*
	 * "idle" = No slide is selected "selected" = A slide is selected
	 */
	public String getCurrentState() {
		return currentState;
	}

	public int getSelectedSlide() {
		return selectedSlideNo;
	}

	public int getSlideCount() {
		return SlideList.getSlides().size();
	}
	
	public String getSlideName(int index)
	{
		return SlideList.getSlides().get(index).getName();
	}

	public void selectSlide(int index) {
		ArrayList<Slide> slides = SlideList.getSlides();

		selectedSlide = slides.get(index - 1);
		selectedSlideNo = index;
		
		currentState = "selected";
	}

	public void deleteButtonPressed() {
		SlideList.deleteSlide(selectedSlide);
	}

	public void moveLeftButtonPressed() {
		if (selectedSlideNo != 1) {
			SlideList.moveLeft(selectedSlide);
			selectedSlideNo--;
		}
	}

	public void moveRightButtonPressed() {
		if (!(selectedSlideNo >= SlideList.getSlides().size())) {
			SlideList.moveRight(selectedSlide);
			selectedSlideNo++;
		}
	}
}